/**
\ *<p>Copyright: Copyright (c) 2012</p> 
 *<p>Company: SCPII</p>
 *<p>Project:optimus-manage</p>
 *@author xiezhouyan
 *@Date 2013-4-29 下午2:18:02
 *@version 1.0
 *@description:
 */
package com.cybertron.ironhide.manage.action;

import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;

import com.cybertron.ironhide.manage.common.base.BaseAction;

public class UserAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7656854382014622597L;

	public String login() {
		if (isAjax()) {
			return ajaxLogout("会话超时请重新登录");
		}
		String message = (String) getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
		if (message != null) {
			if ("com.cybertron.ironhide.manage.common.exception.IncorrectCaptchaException"
					.equals(message)) {
				addActionError("验证码错误,请重新输入!");
			} else if ("org.apache.shiro.authc.IncorrectCredentialsException"
					.equals(message)
					|| "org.apache.shiro.authc.UnknownAccountException"
							.equals(message)) {
				addActionError("您的用户名或密码错误!");
			} else if ("org.apache.shiro.authc.DisabledAccountException"
					.equals(message)) {
				addActionError("您的账号已被禁用,无法登录!");
			} else if ("org.apache.shiro.authc.LockedAccountException"
					.equals(message)) {
				addActionError("您的账号已被锁定,无法登录!");
			} else {
				addActionError("出现未知错误,无法登录!");
			}
		}
		return LOGIN;
	}

	public String unauthorized() {
		if (isAjax()) {
			return ajaxError("无访问权限");
		}
		addActionError("无访问权限");
		return LOGIN;
	}

}
